package cn.golxen.user.controller;


import cn.golxen.commons.entity.Result;
import cn.golxen.commons.vo.UserAddVo;
import cn.golxen.user.entity.User;
import cn.golxen.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    UserService userService;

    @PostMapping(value = "/adduser")
    public Result addUser(@RequestBody User user){
        if (userService.addUser(user)==0)
            return new Result(6,"账号已存在");
        return new Result(200,"注册成功");
    }
    @GetMapping(value = "/{userId}")
    public Result selectUserById(@PathVariable(value = "userId") String userId){
        User user=userService.selectUserById(userId);
        return Result.successResult(user);
    }
    @PostMapping(value = "/login")
    public Result userLogin(@RequestBody User user){
        if (userService.userLogin(user)){
            return new Result(200,"登录成功");
        }else
            return new Result(7,"登录失败");

    }


}
